<template>
  <!-- 通知详情 -->
  <!-- <h-modal
    class="event-modal"
    hideFooter
    v-model="show"
    title="通知详情"
    @submit="show=false"
    @cancel="$emit('cancel')">
    <div class="notice-scorll">

    </div>
  </h-modal> -->
  <div>
    <a-modal v-model="show" title="历史记录">
      <div class="notice-scorll">
        <div style="text-align: center">
          <a-radio-group v-model="params.status" @change="onChange" button-style="solid">
            <a-radio-button :value="0">
              日常通知
            </a-radio-button>
            <a-radio-button :value="1">
              重要通知
            </a-radio-button>
          </a-radio-group>
        </div>
        <a-list item-layout="horizontal" :data-source="data">
          <a-list-item slot="renderItem" slot-scope="item" >
            <a-list-item-meta>
              <span class="description" slot="title" @click="showDetails(item)">
                通知人：{{ item.createBy }}
              </span>
              <span class="description" slot="description" @click="showDetails(item)">
                {{ item.content }}
              </span>
            </a-list-item-meta>
            <div>{{ item.createTime }}</div>
          </a-list-item>
        </a-list>
      </div>
      <span slot="footer">
        <a-button type="primary" @click="show = false">确定</a-button>
      </span>
    </a-modal>
    <NoticeDetail v-model="showDetail" :id="ids" />
  </div>
</template>

<script>
import moment from 'moment';
import { queryIssHistory } from '@/api/notice';
import NoticeDetail from './NoticeDetail';

// import cloneDeep from 'lodash/cloneDeep';

export default {
  props: {
    showModal: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
      default: ''
    }
  },
  components: {
    NoticeDetail
  },
  model: {
    prop: 'showModal',
    event: 'update:showModal'
  },
  watch: {
    showModal: {
      handler(val) {
        this.show = val;
        if (val) {
          this.queryIssHistory();
        }
      },
      immediate: true
    },
    show(val) {
      this.$emit('update:showModal', val);
    }
  },
  mounted() {
    this.$nextTick(() => {
       if (document.querySelector('.notice-scorll')) {
          const selectWrap = document.querySelector('.notice-scorll');
          selectWrap.addEventListener('scroll', this.scrollLoadMore);
       }
    });
  },
  data() {
    return {
      showDetail: false,
      ids: '',
      moment,
      // value: '0',
      show: false,
      eventDetailInfo: {},
      data: [],
      weightType: {
        0: '低',
        1: '中',
        2: '高'
      },
      params: {
        pageNo: 1,
        pageSize: 10,
        status: 0
      },
      loading: false,
      finished: false
    };
  },
  methods: {
    queryIssHistory() {
      this.loading = true;
      queryIssHistory(this.params).then(res => {
        this.data = this.data.concat(res.data.records);
        this.total = res.data.total;
        this.loading = false;
        if (this.data.length >= this.total) {
          this.finished = true;
        }
      });
    },
    scrollLoadMore() {
      if (this.loading || this.finished) return;
      const scrollWrap = document.querySelector('.notice-scorll');
      var currentScrollTop = scrollWrap.scrollTop;
      var currentOffsetHeight = scrollWrap.scrollHeight;
      var currentClientHeight = scrollWrap.clientHeight;
      if ((currentScrollTop + currentClientHeight >= currentOffsetHeight - 80)) {
          // 到底部了 重新请求数据
          this.params.pageNo++; // 页码++
          this.queryIssHistory();
       }
    },
    onChange() {
      this.data = [];
      this.finished = false;
      this.params.pageNo = 1;
      this.queryIssHistory();
    },
    showDetails({ id }) {
      this.ids = id;
      this.showDetail = true;
    }
  }
};
</script>

<style lang="less" scoped>
  .detail-title {
    // display: flex;
    // justify-content: center;
    // align-items: center;
    // margin-top: -20px;
    .detail-tag {
      width: 57px;
      height: 26px;
      border: 1px solid #1FAF7A;
      border-radius: 5px;
      font-size: 16px;
      font-weight: 400;
      color: #1FAF7A;
      text-align: center;
      line-height: 25px;
      margin-right: 13px;
      transform: translate(0, 1px);
    }
    h1 {
      font-size: 20px;
      font-weight: 500;
      color: #1F3B8A;
      margin: 0;
      line-height: 1.1;
      max-width: 70%;
    }
  }
  .detail-tags {
    font-size: 16px;
    font-weight: 400;
    color: #0478FE;
    margin: 0 auto;
    text-align: center;
    margin-top: 18px;
    .ant-divider {
      background: #0478FE;
    }
  }
  .detail-weightType {
    font-size: 16px;
    font-weight: 400;
    color: #0478FE;
    margin-left: 12px;
    line-height: 1;
  }
  .detail-content {
    margin-top: 20px;
    color: #333;
    font-size: 16px;
    line-height: 2;
    >p {

    }
    img {
      max-width: 100%;
    }
  }
  .notice-scorll {
    overflow-y: auto;
    height: 400px;
    &::-webkit-scrollbar {
      width: 8px;
      height: 1px;
    }
    &::-webkit-scrollbar-thumb {
        border-radius: 10px;
        background: #1F3B8A;
      }
    &::-webkit-scrollbar-track {
      border-radius: 10px;
      background: #EDEDED;
    }
  }
  .description {
    &:hover {
      color: #1F3B8A;
      cursor: pointer;
    }
  }
</style>
